﻿using System;
using System.Collections.Generic;
using System.IO;
using DroidClaim.DAL.Dal;
using DroidClaim.DAL.Entities;
using FluentNHibernate.Automapping;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using DroidClaim.Service.Dto;
using DroidClaim.DAL.Models;
using System.ServiceModel.Activation;
using System.Reflection;

namespace DroidClaim.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service.svc or Service.svc.cs at the Solution Explorer and start debugging.
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service : IService
    {
        private readonly ISession _session;
        private readonly ISessionFactory _sessionFactory;

        public Service()
        {
            var appReader = new System.Configuration.AppSettingsReader();
            var connectionString = Convert.ToString(appReader.GetValue("connectionString", typeof(string)));
            var mappingScriptPath = AppDomain.CurrentDomain.BaseDirectory + "/db_mappings";
            if (!Directory.Exists(mappingScriptPath))
                Directory.CreateDirectory(mappingScriptPath);

            _sessionFactory = Fluently.Configure()
                .Database(
                    MsSqlConfiguration.MsSql2008
                    .ConnectionString(@connectionString))
                    .Mappings(x => x.AutoMappings.Add(AutoMap.AssemblyOf<ClaimInfo>().Where(t => t.Namespace != null && t.Namespace.EndsWith("Entities"))).ExportTo(@mappingScriptPath))
                    //.ExposeConfiguration(BuildSchema) // ********** ใช้ครั้งแรกเท่านั้น (กรณียังไม่มี Table)
                    .BuildSessionFactory();
            _session = _sessionFactory.OpenSession();
        }

        private void BuildSchema(Configuration config)
        {
            new SchemaExport(config).Create(false, true);
        }

        /*public Service(ISession session)
        {
            this._session = session;   
        }*/

		#region ClaimInfo methods

        public ResponseDto<ClaimInfoDto> AddClaimInfo(ClaimInfoDto arg)
        {
            var result = new Dto.ResponseDto<ClaimInfoDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new ClaimInfoDAL(_session);
                    var obj = TransformDto2ClaimInfo(arg);
                    dal.Add(obj);
                    _session.Transaction.Commit();
                    result.Data = TransformClaimInfo2Dto(obj);
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<ClaimInfoDto> DeleteClaimInfo(List<string> arg)
        {
            var result = new Dto.ResponseDto<ClaimInfoDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var obj = new ClaimInfoDAL(_session);
                    obj.Delete(arg);
                    _session.Transaction.Commit();
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<List<ClaimInfoDto>> GetAllClaimInfo(GetAllClaimInfoRequestDto arg)
        {
            var result = new Dto.ResponseDto<List<ClaimInfoDto>>();
            try
            {
                var dal = new ClaimInfoDAL(_session);

                ClaimInfoSearch search = null;
                if (arg != null)
                {
                    search = new ClaimInfoSearch
                    {
                        Id = arg.Id,
                        Customer = TransformDto2Customer(arg.Customer),
                        Surveyor = TransformDto2Surveyor(arg.Surveyor),
					    Code = arg.Code,
					    Name = arg.Name,
						Sort = arg.Sort,
                        SortType = arg.SortType,
                    };
                }

                var list = dal.GetAll(search);
                result.Data = new List<ClaimInfoDto>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dto = TransformClaimInfo2Dto(item);
                        result.Data.Add(dto);
                    }
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.ErrorMessage = ex.Message;
            }
            return result;
        }

        public ResponseDto<ClaimInfoDto> UpdateClaimInfo(ClaimInfoDto arg)
        {
            var result = new Dto.ResponseDto<ClaimInfoDto>();

            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new ClaimInfoDAL(_session);
                    var obj = TransformDto2ClaimInfo(arg);
                    dal.Update(obj);
                    _session.Transaction.Commit();
                    result.Status = true;

                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        private ClaimInfoDto TransformClaimInfo2Dto(ClaimInfo arg)
        {
            var dto = new ClaimInfoDto();
            if (null != arg)
            {
								dto.Id = arg.Id;
												dto.AccidentDate = arg.AccidentDate;
												dto.AccidentLocation = arg.AccidentLocation;
												dto.Latitude = arg.Latitude;
												dto.Longitude = arg.Longitude;
												dto.UpdateDate = arg.UpdateDate;
												dto.AccImgPath = arg.AccImgPath;
												dto.CliamDocImgPath = arg.CliamDocImgPath;
												//dto.ClaimStatus = new ClaimStatusDto();
					if (null != arg.ClaimStatus)
						{
						dto.ClaimStatus = new ClaimStatusDto();
					                    dto.ClaimStatus.Id = arg.ClaimStatus.Id;
				                    dto.ClaimStatus.Name = arg.ClaimStatus.Name;
				                    dto.ClaimStatus.Code = arg.ClaimStatus.Code;
								}
												//dto.CliamDoc = new CliamDocDto();
					if (null != arg.CliamDoc)
						{
						dto.CliamDoc = new CliamDocDto();
					                    dto.CliamDoc.Id = arg.CliamDoc.Id;
				                    dto.CliamDoc.CliamDocImgPath = arg.CliamDoc.CliamDocImgPath;
				                    dto.CliamDoc.Code = arg.CliamDoc.Code;
				                    dto.CliamDoc.Name = arg.CliamDoc.Name;
								}
												//dto.Customer = new CustomerDto();
					if (null != arg.Customer)
						{
						dto.Customer = new CustomerDto();
					                    dto.Customer.Id = arg.Customer.Id;
				                    dto.Customer.LicensePlate = arg.Customer.LicensePlate;
				                    dto.Customer.Salt = arg.Customer.Salt;
				                    dto.Customer.Name = arg.Customer.Name;
				                    dto.Customer.Surname = arg.Customer.Surname;
				                    dto.Customer.Mobile = arg.Customer.Mobile;
				                    dto.Customer.Email = arg.Customer.Email;
				                    dto.Customer.CustImgPath = arg.Customer.CustImgPath;
				                    dto.Customer.Password = arg.Customer.Password;
				                    dto.Customer.CarImgPath = arg.Customer.CarImgPath;
				                    dto.Customer.CarBrand = arg.Customer.CarBrand;
				                    dto.Customer.CarModel = arg.Customer.CarModel;
				                    dto.Customer.InsurancePackage = arg.Customer.InsurancePackage;
				                    dto.Customer.Code = arg.Customer.Code;
								}
												//dto.Surveyor = new SurveyorDto();
					if (null != arg.Surveyor)
						{
						dto.Surveyor = new SurveyorDto();
					                    dto.Surveyor.Id = arg.Surveyor.Id;
				                    dto.Surveyor.SurveyerId = arg.Surveyor.SurveyerId;
				                    dto.Surveyor.Username = arg.Surveyor.Username;
				                    dto.Surveyor.Password = arg.Surveyor.Password;
				                    dto.Surveyor.Salt = arg.Surveyor.Salt;
				                    dto.Surveyor.Name = arg.Surveyor.Name;
				                    dto.Surveyor.Surname = arg.Surveyor.Surname;
				                    dto.Surveyor.Mobile = arg.Surveyor.Mobile;
				                    dto.Surveyor.Email = arg.Surveyor.Email;
				                    dto.Surveyor.PicturePath = arg.Surveyor.PicturePath;
				                    dto.Surveyor.Code = arg.Surveyor.Code;
				                   // dto.Surveyor.SurveyorLocation = TransformSurveyorLocation2Dto(arg.Surveyor.SurveyorLocation);
								}
												dto.Code = arg.Code;
												dto.Name = arg.Name;
												//dto.ClaimNumber = new ClaimNumberDto();
					if (null != arg.ClaimNumber)
						{
						dto.ClaimNumber = new ClaimNumberDto();
					                    dto.ClaimNumber.Id = arg.ClaimNumber.Id;
				                    dto.ClaimNumber.Code = arg.ClaimNumber.Code;
				                    dto.ClaimNumber.Name = arg.ClaimNumber.Name;
								}
							            }
            return dto;
        }

        private ClaimInfo TransformDto2ClaimInfo(ClaimInfoDto arg)
        {
            //var obj = new ClaimInfo();
			var obj = _session.Get("ClaimInfo", arg.Id) as ClaimInfo;
            if (obj == null)
                obj = new ClaimInfo();
            if (null != arg)
            {
			                obj.Id = arg.Id;
			                obj.AccidentDate = arg.AccidentDate;
			                obj.AccidentLocation = arg.AccidentLocation;
			                obj.Latitude = arg.Latitude;
			                obj.Longitude = arg.Longitude;
			                obj.UpdateDate = arg.UpdateDate;
			                obj.AccImgPath = arg.AccImgPath;
			                obj.CliamDocImgPath = arg.CliamDocImgPath;
						obj.ClaimStatus = EntityMapper(obj.ClaimStatus, arg.ClaimStatus);
						obj.CliamDoc = EntityMapper(obj.CliamDoc, arg.CliamDoc);
						obj.Customer = EntityMapper(obj.Customer, arg.Customer);
						obj.Surveyor = EntityMapper(obj.Surveyor, arg.Surveyor);
			                obj.Code = arg.Code;
			                obj.Name = arg.Name;
						obj.ClaimNumber = EntityMapper(obj.ClaimNumber, arg.ClaimNumber);
			            }
            return obj;
        }
        #endregion

		        #region ClaimStatus methods

        public ResponseDto<ClaimStatusDto> AddClaimStatus(ClaimStatusDto arg)
        {
            var result = new Dto.ResponseDto<ClaimStatusDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new ClaimStatusDAL(_session);
                    var obj = TransformDto2ClaimStatus(arg);
                    dal.Add(obj);
                    _session.Transaction.Commit();
                    result.Data = TransformClaimStatus2Dto(obj);
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<ClaimStatusDto> DeleteClaimStatus(List<string> arg)
        {
            var result = new Dto.ResponseDto<ClaimStatusDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var obj = new ClaimStatusDAL(_session);
                    obj.Delete(arg);
                    _session.Transaction.Commit();
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<List<ClaimStatusDto>> GetAllClaimStatus(GetAllClaimStatusRequestDto arg)
        {
            var result = new Dto.ResponseDto<List<ClaimStatusDto>>();
            try
            {
                var dal = new ClaimStatusDAL(_session);

                ClaimStatusSearch search = null;
                if (arg != null)
                {
                    search = new ClaimStatusSearch
                    {
					                        Name = arg.Name,
					                        Code = arg.Code,
										Sort = arg.Sort,
                    SortType = arg.SortType,
                    };
                }

                var list = dal.GetAll(search);
                result.Data = new List<ClaimStatusDto>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dto = TransformClaimStatus2Dto(item);
                        result.Data.Add(dto);
                    }
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.ErrorMessage = ex.Message;
            }
            return result;
        }

        public ResponseDto<ClaimStatusDto> UpdateClaimStatus(ClaimStatusDto arg)
        {
            var result = new Dto.ResponseDto<ClaimStatusDto>();

            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new ClaimStatusDAL(_session);
                    var obj = TransformDto2ClaimStatus(arg);
                    dal.Update(obj);
                    _session.Transaction.Commit();
                    result.Status = true;

                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        private ClaimStatusDto TransformClaimStatus2Dto(ClaimStatus arg)
        {
            var dto = new ClaimStatusDto();
            if (null != arg)
            {
								dto.Id = arg.Id;
												dto.Name = arg.Name;
												dto.Code = arg.Code;
							            }
            return dto;
        }

        private ClaimStatus TransformDto2ClaimStatus(ClaimStatusDto arg)
        {
            if (arg == null)
            {
                return null;
            }

            //var obj = new ClaimStatus();
			var obj = _session.Get("ClaimStatus", arg.Id) as ClaimStatus;
            if (obj == null)
                obj = new ClaimStatus();
            if (null != arg)
            {
			                obj.Id = arg.Id;
			                obj.Name = arg.Name;
			                obj.Code = arg.Code;
			            }
            return obj;
        }
        #endregion

		        #region CliamDoc methods

        public ResponseDto<CliamDocDto> AddCliamDoc(CliamDocDto arg)
        {
            var result = new Dto.ResponseDto<CliamDocDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new CliamDocDAL(_session);
                    var obj = TransformDto2CliamDoc(arg);
                    dal.Add(obj);
                    _session.Transaction.Commit();
                    result.Data = TransformCliamDoc2Dto(obj);
                    result.Status = true;
                    //result.Data = obj;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<CliamDocDto> DeleteCliamDoc(List<string> arg)
        {
            var result = new Dto.ResponseDto<CliamDocDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var obj = new CliamDocDAL(_session);
                    obj.Delete(arg);
                    _session.Transaction.Commit();
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<List<CliamDocDto>> GetAllCliamDoc(GetAllCliamDocRequestDto arg)
        {
            var result = new Dto.ResponseDto<List<CliamDocDto>>();
            try
            {
                var dal = new CliamDocDAL(_session);

                CliamDocSearch search = null;
                if (arg != null)
                {
                    search = new CliamDocSearch
                    {
					                        Code = arg.Code,
					                        Name = arg.Name,
										Sort = arg.Sort,
                    SortType = arg.SortType,
                    };
                }

                var list = dal.GetAll(search);
                result.Data = new List<CliamDocDto>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dto = TransformCliamDoc2Dto(item);
                        result.Data.Add(dto);
                    }
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.ErrorMessage = ex.Message;
            }
            return result;
        }

        public ResponseDto<CliamDocDto> UpdateCliamDoc(CliamDocDto arg)
        {
            var result = new Dto.ResponseDto<CliamDocDto>();

            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new CliamDocDAL(_session);
                    var obj = TransformDto2CliamDoc(arg);
                    dal.Update(obj);
                    _session.Transaction.Commit();
                    result.Status = true;

                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        private CliamDocDto TransformCliamDoc2Dto(CliamDoc arg)
        {
            var dto = new CliamDocDto();
            if (null != arg)
            {
								dto.Id = arg.Id;
												dto.CliamDocImgPath = arg.CliamDocImgPath;
												dto.Code = arg.Code;
												dto.Name = arg.Name;
							            }
            return dto;
        }

        private CliamDoc TransformDto2CliamDoc(CliamDocDto arg)
        {
            if (arg == null)
            {
                return null;
            }

            //var obj = new CliamDoc();
			var obj = _session.Get("CliamDoc", arg.Id) as CliamDoc;
            if (obj == null)
                obj = new CliamDoc();
            if (null != arg)
            {
			                obj.Id = arg.Id;
			                obj.CliamDocImgPath = arg.CliamDocImgPath;
			                obj.Code = arg.Code;
			                obj.Name = arg.Name;
			            }
            return obj;
        }
        #endregion

		        #region Customer methods

        public ResponseDto<CustomerDto> AddCustomer(CustomerDto arg)
        {
            var result = new Dto.ResponseDto<CustomerDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new CustomerDAL(_session);
                    var obj = TransformDto2Customer(arg);
                    dal.Add(obj);
                    _session.Transaction.Commit();
                    result.Data = TransformCustomer2Dto(obj);
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<CustomerDto> DeleteCustomer(List<string> arg)
        {
            var result = new Dto.ResponseDto<CustomerDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var obj = new CustomerDAL(_session);
                    obj.Delete(arg);
                    _session.Transaction.Commit();
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<List<CustomerDto>> GetAllCustomer(GetAllCustomerRequestDto arg)
        {
            var result = new Dto.ResponseDto<List<CustomerDto>>();
            try
            {
                var dal = new CustomerDAL(_session);

                CustomerSearch search = null;
                if (arg != null)
                {
                    search = new CustomerSearch
                    {
					                        LicensePlate = arg.LicensePlate,
					                        Salt = arg.Salt,
					                        Name = arg.Name,
					                        Code = arg.Code,
										Sort = arg.Sort,
                    SortType = arg.SortType,
                    };
                }

                var list = dal.GetAll(search);
                result.Data = new List<CustomerDto>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dto = TransformCustomer2Dto(item);
                        result.Data.Add(dto);
                    }
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.ErrorMessage = ex.Message;
            }
            return result;
        }

        public ResponseDto<CustomerDto> UpdateCustomer(CustomerDto arg)
        {
            var result = new Dto.ResponseDto<CustomerDto>();

            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new CustomerDAL(_session);
                    var obj = TransformDto2Customer(arg);
                    dal.Update(obj);
                    _session.Transaction.Commit();
                    result.Status = true;

                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        private CustomerDto TransformCustomer2Dto(Customer arg)
        {
            var dto = new CustomerDto();
            if (null != arg)
            {
								dto.Id = arg.Id;
												dto.LicensePlate = arg.LicensePlate;
												dto.Salt = arg.Salt;
												dto.Name = arg.Name;
												dto.Surname = arg.Surname;
												dto.Mobile = arg.Mobile;
												dto.Email = arg.Email;
												dto.CustImgPath = arg.CustImgPath;
												dto.Password = arg.Password;
												dto.CarImgPath = arg.CarImgPath;
												dto.CarBrand = arg.CarBrand;
												dto.CarModel = arg.CarModel;
												dto.InsurancePackage = arg.InsurancePackage;
												dto.Code = arg.Code;
							            }
            return dto;
        }

        private Customer TransformDto2Customer(CustomerDto arg)
        {
            if (arg == null)
            {
                return null;
            }

            //var obj = new Customer();
			var obj = _session.Get("Customer", arg.Id) as Customer;
            if (obj == null)
                obj = new Customer();
            if (null != arg)
            {
			                obj.Id = arg.Id;
			                obj.LicensePlate = arg.LicensePlate;
			                obj.Salt = arg.Salt;
			                obj.Name = arg.Name;
			                obj.Surname = arg.Surname;
			                obj.Mobile = arg.Mobile;
			                obj.Email = arg.Email;
			                obj.CustImgPath = arg.CustImgPath;
			                obj.Password = arg.Password;
			                obj.CarImgPath = arg.CarImgPath;
			                obj.CarBrand = arg.CarBrand;
			                obj.CarModel = arg.CarModel;
			                obj.InsurancePackage = arg.InsurancePackage;
			                obj.Code = arg.Code;
			            }
            return obj;
        }
        #endregion

		        #region RejectedHistory methods

        public ResponseDto<RejectedHistoryDto> AddRejectedHistory(RejectedHistoryDto arg)
        {
            var result = new Dto.ResponseDto<RejectedHistoryDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new RejectedHistoryDAL(_session);
                    var obj = TransformDto2RejectedHistory(arg);
                    dal.Add(obj);
                    _session.Transaction.Commit();
                    result.Data = TransformRejectedHistory2Dto(obj);
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<RejectedHistoryDto> DeleteRejectedHistory(List<string> arg)
        {
            var result = new Dto.ResponseDto<RejectedHistoryDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var obj = new RejectedHistoryDAL(_session);
                    obj.Delete(arg);
                    _session.Transaction.Commit();
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<List<RejectedHistoryDto>> GetAllRejectedHistory(GetAllRejectedHistoryRequestDto arg)
        {
            var result = new Dto.ResponseDto<List<RejectedHistoryDto>>();
            try
            {
                var dal = new RejectedHistoryDAL(_session);

                RejectedHistorySearch search = null;
                if (arg != null)
                {
                    search = new RejectedHistorySearch
                    {
					                        Code = arg.Code,
					                        Name = arg.Name,
										Sort = arg.Sort,
                    SortType = arg.SortType,
                    };
                }

                var list = dal.GetAll(search);
                result.Data = new List<RejectedHistoryDto>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dto = TransformRejectedHistory2Dto(item);
                        result.Data.Add(dto);
                    }
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.ErrorMessage = ex.Message;
            }
            return result;
        }

        public ResponseDto<RejectedHistoryDto> UpdateRejectedHistory(RejectedHistoryDto arg)
        {
            var result = new Dto.ResponseDto<RejectedHistoryDto>();

            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new RejectedHistoryDAL(_session);
                    var obj = TransformDto2RejectedHistory(arg);
                    dal.Update(obj);
                    _session.Transaction.Commit();
                    result.Status = true;

                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        private RejectedHistoryDto TransformRejectedHistory2Dto(RejectedHistory arg)
        {
            var dto = new RejectedHistoryDto();
            if (null != arg)
            {
								dto.Id = arg.Id;
												dto.Reason = arg.Reason;
												//dto.ClaimInfo = new ClaimInfoDto();
					if (null != arg.ClaimInfo)
						{
						dto.ClaimInfo = new ClaimInfoDto();
					                    dto.ClaimInfo.Id = arg.ClaimInfo.Id;
				                    dto.ClaimInfo.AccidentDate = arg.ClaimInfo.AccidentDate;
				                    dto.ClaimInfo.AccidentLocation = arg.ClaimInfo.AccidentLocation;
				                    dto.ClaimInfo.Latitude = arg.ClaimInfo.Latitude;
				                    dto.ClaimInfo.Longitude = arg.ClaimInfo.Longitude;
				                    dto.ClaimInfo.UpdateDate = arg.ClaimInfo.UpdateDate;
				                    dto.ClaimInfo.AccImgPath = arg.ClaimInfo.AccImgPath;
				                    dto.ClaimInfo.CliamDocImgPath = arg.ClaimInfo.CliamDocImgPath;
				                   // dto.ClaimInfo.ClaimStatus = TransformClaimStatus2Dto(arg.ClaimInfo.ClaimStatus);
				                   // dto.ClaimInfo.CliamDoc = TransformCliamDoc2Dto(arg.ClaimInfo.CliamDoc);
				                   // dto.ClaimInfo.Customer = TransformCustomer2Dto(arg.ClaimInfo.Customer);
				                   // dto.ClaimInfo.Surveyor = TransformSurveyor2Dto(arg.ClaimInfo.Surveyor);
				                    dto.ClaimInfo.Code = arg.ClaimInfo.Code;
				                    dto.ClaimInfo.Name = arg.ClaimInfo.Name;
				                   // dto.ClaimInfo.ClaimNumber = TransformClaimNumber2Dto(arg.ClaimInfo.ClaimNumber);
								}
												//dto.Surveyor = new SurveyorDto();
					if (null != arg.Surveyor)
						{
						dto.Surveyor = new SurveyorDto();
					                    dto.Surveyor.Id = arg.Surveyor.Id;
				                    dto.Surveyor.SurveyerId = arg.Surveyor.SurveyerId;
				                    dto.Surveyor.Username = arg.Surveyor.Username;
				                    dto.Surveyor.Password = arg.Surveyor.Password;
				                    dto.Surveyor.Salt = arg.Surveyor.Salt;
				                    dto.Surveyor.Name = arg.Surveyor.Name;
				                    dto.Surveyor.Surname = arg.Surveyor.Surname;
				                    dto.Surveyor.Mobile = arg.Surveyor.Mobile;
				                    dto.Surveyor.Email = arg.Surveyor.Email;
				                    dto.Surveyor.PicturePath = arg.Surveyor.PicturePath;
				                    dto.Surveyor.Code = arg.Surveyor.Code;
				                   // dto.Surveyor.SurveyorLocation = TransformSurveyorLocation2Dto(arg.Surveyor.SurveyorLocation);
								}
												dto.Code = arg.Code;
												dto.Name = arg.Name;
							            }
            return dto;
        }

        private RejectedHistory TransformDto2RejectedHistory(RejectedHistoryDto arg)
        {
            if (arg == null)
            {
                return null;
            }

            //var obj = new RejectedHistory();
			var obj = _session.Get("RejectedHistory", arg.Id) as RejectedHistory;
            if (obj == null)
                obj = new RejectedHistory();
            if (null != arg)
            {
			                obj.Id = arg.Id;
			                obj.Reason = arg.Reason;
						obj.ClaimInfo = EntityMapper(obj.ClaimInfo, arg.ClaimInfo);
						obj.Surveyor = EntityMapper(obj.Surveyor, arg.Surveyor);
			                obj.Code = arg.Code;
			                obj.Name = arg.Name;
			            }
            return obj;
        }
        #endregion

		        #region Surveyor methods

        public ResponseDto<SurveyorDto> AddSurveyor(SurveyorDto arg)
        {
            var result = new Dto.ResponseDto<SurveyorDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new SurveyorDAL(_session);
                    var obj = TransformDto2Surveyor(arg);
                    dal.Add(obj);
                    _session.Transaction.Commit();
                    result.Data = TransformSurveyor2Dto(obj);
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<SurveyorDto> DeleteSurveyor(List<string> arg)
        {
            var result = new Dto.ResponseDto<SurveyorDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var obj = new SurveyorDAL(_session);
                    obj.Delete(arg);
                    _session.Transaction.Commit();
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<List<SurveyorDto>> GetAllSurveyor(GetAllSurveyorRequestDto arg)
        {
            var result = new Dto.ResponseDto<List<SurveyorDto>>();
            try
            {
                var dal = new SurveyorDAL(_session);

                SurveyorLocation surveyorLocation = null;
                if (arg.SurveyorLocation != null)
                {
                    surveyorLocation = TransformDto2SurveyorLocation(arg.SurveyorLocation);
                }

                SurveyorSearch search = null;
                if (arg != null)
                {
                    search = new SurveyorSearch
                    {
					    SurveyerId = arg.SurveyerId,
					    Username = arg.Username,
                        SurveyorLocation = surveyorLocation,
					    Name = arg.Name,
					    Code = arg.Code,
						Sort = arg.Sort,
                    SortType = arg.SortType,
                    };
                }

                var list = dal.GetAll(search);
                result.Data = new List<SurveyorDto>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dto = TransformSurveyor2Dto(item);
                        result.Data.Add(dto);
                    }
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.ErrorMessage = ex.Message;
            }
            return result;
        }

        public ResponseDto<SurveyorDto> UpdateSurveyor(SurveyorDto arg)
        {
            var result = new Dto.ResponseDto<SurveyorDto>();

            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new SurveyorDAL(_session);
                    var obj = TransformDto2Surveyor(arg);
                    dal.Update(obj);
                    _session.Transaction.Commit();
                    result.Status = true;

                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        private SurveyorDto TransformSurveyor2Dto(Surveyor arg)
        {
            var dto = new SurveyorDto();
            if (null != arg)
            {
								dto.Id = arg.Id;
												dto.SurveyerId = arg.SurveyerId;
												dto.Username = arg.Username;
												dto.Password = arg.Password;
												dto.Salt = arg.Salt;
												dto.Name = arg.Name;
												dto.Surname = arg.Surname;
												dto.Mobile = arg.Mobile;
												dto.Email = arg.Email;
												dto.PicturePath = arg.PicturePath;
												dto.Code = arg.Code;
												//dto.SurveyorLocation = new SurveyorLocationDto();
					if (null != arg.SurveyorLocation)
						{
						dto.SurveyorLocation = new SurveyorLocationDto();
					                    dto.SurveyorLocation.Id = arg.SurveyorLocation.Id;
				                    dto.SurveyorLocation.Latitude = arg.SurveyorLocation.Latitude;
				                    dto.SurveyorLocation.Longitude = arg.SurveyorLocation.Longitude;
				                    dto.SurveyorLocation.Code = arg.SurveyorLocation.Code;
				                    dto.SurveyorLocation.Name = arg.SurveyorLocation.Name;
				                    dto.SurveyorLocation.Status = arg.SurveyorLocation.Status;
								}
							            }
            return dto;
        }

        private Surveyor TransformDto2Surveyor(SurveyorDto arg)
        {
            if (arg == null)
            {
                return null;
            }

            //var obj = new Surveyor();
			var obj = _session.Get("Surveyor", arg.Id) as Surveyor;
            if (obj == null)
                obj = new Surveyor();

            /*SurveyorLocation location = null;
            if(arg.SurveyorLocation!=null){
                location = TransformDto2SurveyorLocation(arg.SurveyorLocation);
            }*/

            if (null != arg)
            {
			                obj.Id = arg.Id;
			                obj.SurveyerId = arg.SurveyerId;
			                obj.Username = arg.Username;
			                obj.Password = arg.Password;
			                obj.Salt = arg.Salt;
			                obj.Name = arg.Name;
			                obj.Surname = arg.Surname;
			                obj.Mobile = arg.Mobile;
			                obj.Email = arg.Email;
			                obj.PicturePath = arg.PicturePath;
			                obj.Code = arg.Code;
						obj.SurveyorLocation = EntityMapper(obj.SurveyorLocation, arg.SurveyorLocation);
                            //obj.SurveyorLocation = location;
			            }
            return obj;
        }
        #endregion

		        #region SurveyorLocation methods

        public ResponseDto<SurveyorLocationDto> AddSurveyorLocation(SurveyorLocationDto arg)
        {
            var result = new Dto.ResponseDto<SurveyorLocationDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new SurveyorLocationDAL(_session);
                    var obj = TransformDto2SurveyorLocation(arg);
                    dal.Add(obj);
                    _session.Transaction.Commit();
                    result.Data = TransformSurveyorLocation2Dto(obj);
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<SurveyorLocationDto> DeleteSurveyorLocation(List<string> arg)
        {
            var result = new Dto.ResponseDto<SurveyorLocationDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var obj = new SurveyorLocationDAL(_session);
                    obj.Delete(arg);
                    _session.Transaction.Commit();
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<List<SurveyorLocationDto>> GetAllSurveyorLocation(GetAllSurveyorLocationRequestDto arg)
        {
            var result = new Dto.ResponseDto<List<SurveyorLocationDto>>();
            try
            {
                var dal = new SurveyorLocationDAL(_session);

                SurveyorLocationSearch search = null;
                if (arg != null)
                {
                    search = new SurveyorLocationSearch
                    {
					                        Code = arg.Code,
					                        Name = arg.Name,
					                        Status = arg.Status,
										Sort = arg.Sort,
                    SortType = arg.SortType,
                    };
                }

                var list = dal.GetAll(search);
                result.Data = new List<SurveyorLocationDto>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dto = TransformSurveyorLocation2Dto(item);
                        result.Data.Add(dto);
                    }
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.ErrorMessage = ex.Message;
            }
            return result;
        }

        public ResponseDto<SurveyorLocationDto> UpdateSurveyorLocation(SurveyorLocationDto arg)
        {
            var result = new Dto.ResponseDto<SurveyorLocationDto>();

            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new SurveyorLocationDAL(_session);
                    var obj = TransformDto2SurveyorLocation(arg);
                    dal.Update(obj);
                    _session.Transaction.Commit();
                    result.Status = true;

                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        private SurveyorLocationDto TransformSurveyorLocation2Dto(SurveyorLocation arg)
        {
            var dto = new SurveyorLocationDto();
            if (null != arg)
            {
								dto.Id = arg.Id;
												dto.Latitude = arg.Latitude;
												dto.Longitude = arg.Longitude;
												dto.Code = arg.Code;
												dto.Name = arg.Name;
												dto.Status = arg.Status;
							            }
            return dto;
        }

        private SurveyorLocation TransformDto2SurveyorLocation(SurveyorLocationDto arg)
        {
            if (arg == null)
            {
                return null;
            }

            //var obj = new SurveyorLocation();
			var obj = _session.Get("SurveyorLocation", arg.Id) as SurveyorLocation;
            if (obj == null)
                obj = new SurveyorLocation();
            if (null != arg)
            {
			                obj.Id = arg.Id;
			                obj.Latitude = arg.Latitude;
			                obj.Longitude = arg.Longitude;
			                obj.Code = arg.Code;
			                obj.Name = arg.Name;
			                obj.Status = arg.Status;
			            }
            return obj;
        }
        #endregion

		        #region ClaimNumber methods

        public ResponseDto<ClaimNumberDto> AddClaimNumber(ClaimNumberDto arg)
        {
            var result = new Dto.ResponseDto<ClaimNumberDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new ClaimNumberDAL(_session);
                    var obj = TransformDto2ClaimNumber(arg);
                    dal.Add(obj);
                    _session.Transaction.Commit();
                    result.Data = TransformClaimNumber2Dto(obj);
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<ClaimNumberDto> DeleteClaimNumber(List<string> arg)
        {
            var result = new Dto.ResponseDto<ClaimNumberDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var obj = new ClaimNumberDAL(_session);
                    obj.Delete(arg);
                    _session.Transaction.Commit();
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<List<ClaimNumberDto>> GetAllClaimNumber(GetAllClaimNumberRequestDto arg)
        {
            var result = new Dto.ResponseDto<List<ClaimNumberDto>>();
            try
            {
                var dal = new ClaimNumberDAL(_session);

                ClaimNumberSearch search = null;
                if (arg != null)
                {
                    search = new ClaimNumberSearch
                    {
					                        Code = arg.Code,
					                        Name = arg.Name,
										Sort = arg.Sort,
                    SortType = arg.SortType,
                    };
                }

                var list = dal.GetAll(search);
                result.Data = new List<ClaimNumberDto>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dto = TransformClaimNumber2Dto(item);
                        result.Data.Add(dto);
                    }
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.ErrorMessage = ex.Message;
            }
            return result;
        }

        public ResponseDto<ClaimNumberDto> UpdateClaimNumber(ClaimNumberDto arg)
        {
            var result = new Dto.ResponseDto<ClaimNumberDto>();

            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new ClaimNumberDAL(_session);
                    var obj = TransformDto2ClaimNumber(arg);
                    dal.Update(obj);
                    _session.Transaction.Commit();
                    result.Status = true;

                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        private ClaimNumberDto TransformClaimNumber2Dto(ClaimNumber arg)
        {
            var dto = new ClaimNumberDto();
            if (null != arg)
            {
								dto.Id = arg.Id;
												dto.Code = arg.Code;
												dto.Name = arg.Name;
							            }
            return dto;
        }

        private ClaimNumber TransformDto2ClaimNumber(ClaimNumberDto arg)
        {
            if (arg == null)
            {
                return null;
            }

            //var obj = new ClaimNumber();
			var obj = _session.Get("ClaimNumber", arg.Id) as ClaimNumber;
            if (obj == null)
                obj = new ClaimNumber();
            if (null != arg)
            {
			                obj.Id = arg.Id;
			                obj.Code = arg.Code;
			                obj.Name = arg.Name;
			            }
            return obj;
        }
        #endregion

		        #region SessionInfo methods

        public ResponseDto<SessionInfoDto> AddSessionInfo(SessionInfoDto arg)
        {
            var result = new Dto.ResponseDto<SessionInfoDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new SessionInfoDAL(_session);
                    var obj = TransformDto2SessionInfo(arg);
                    dal.Add(obj);
                    _session.Transaction.Commit();
                    result.Data = TransformSessionInfo2Dto(obj);
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<SessionInfoDto> DeleteSessionInfo(List<string> arg)
        {
            var result = new Dto.ResponseDto<SessionInfoDto>();
            using (_session.BeginTransaction())
            {
                try
                {
                    var obj = new SessionInfoDAL(_session);
                    obj.Delete(arg);
                    _session.Transaction.Commit();
                    result.Status = true;
                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        public ResponseDto<List<SessionInfoDto>> GetAllSessionInfo(GetAllSessionInfoRequestDto arg)
        {
            var result = new Dto.ResponseDto<List<SessionInfoDto>>();
            try
            {
                var dal = new SessionInfoDAL(_session);

                Customer customer = null;
                if (arg.Customer != null)
                {
                    customer = TransformDto2Customer(arg.Customer);
                }

                Surveyor surveyor = null;
                if (arg.Surveyor != null)
                {
                    surveyor = TransformDto2Surveyor(arg.Surveyor);
                }


                SessionInfoSearch search = null;
                if (arg != null)
                {
                    search = new SessionInfoSearch
                    {
                        SessionId = arg.SessionId,
                        RegistrationId = arg.RegistrationId,
                        Customer = customer,
                        Surveyor = surveyor,
                        Sort = arg.Sort,
                        SortType = arg.SortType,
                    };
                }

                var list = dal.GetAll(search);
                result.Data = new List<SessionInfoDto>();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        var dto = TransformSessionInfo2Dto(item);
                        result.Data.Add(dto);
                    }
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.ErrorMessage = ex.Message;
            }
            return result;
        }

        public ResponseDto<SessionInfoDto> UpdateSessionInfo(SessionInfoDto arg)
        {
            var result = new Dto.ResponseDto<SessionInfoDto>();

            using (_session.BeginTransaction())
            {
                try
                {
                    var dal = new SessionInfoDAL(_session);
                    var obj = TransformDto2SessionInfo(arg);
                    dal.Update(obj);
                    _session.Transaction.Commit();
                    result.Status = true;

                }
                catch (Exception ex)
                {
                    _session.Transaction.Rollback();
                    result.Status = false;
                    result.ErrorMessage = ex.Message;
                }
            }
            return result;
        }

        private SessionInfoDto TransformSessionInfo2Dto(SessionInfo arg)
        {
            var dto = new SessionInfoDto();
            if (null != arg)
            {
								dto.Id = arg.Id;
												dto.UpdateTime = arg.UpdateTime;
												dto.SessionId = arg.SessionId;
					if (null != arg.Surveyor)
						{
						dto.Surveyor = new SurveyorDto();
					                    dto.Surveyor.Id = arg.Surveyor.Id;
				                    dto.Surveyor.SurveyerId = arg.Surveyor.SurveyerId;
				                    dto.Surveyor.Username = arg.Surveyor.Username;
				                    dto.Surveyor.Password = arg.Surveyor.Password;
				                    dto.Surveyor.Salt = arg.Surveyor.Salt;
				                    dto.Surveyor.Name = arg.Surveyor.Name;
				                    dto.Surveyor.Surname = arg.Surveyor.Surname;
				                    dto.Surveyor.Mobile = arg.Surveyor.Mobile;
				                    dto.Surveyor.Email = arg.Surveyor.Email;
				                    dto.Surveyor.PicturePath = arg.Surveyor.PicturePath;
				                    dto.Surveyor.Code = arg.Surveyor.Code;
				                    dto.Surveyor.SurveyorLocation = TransformSurveyorLocation2Dto(arg.Surveyor.SurveyorLocation);
								}
												//dto.Customer = new CustomerDto();
					if (null != arg.Customer)
						{
						dto.Customer = new CustomerDto();
					                    dto.Customer.Id = arg.Customer.Id;
				                    dto.Customer.LicensePlate = arg.Customer.LicensePlate;
				                    dto.Customer.Salt = arg.Customer.Salt;
				                    dto.Customer.Name = arg.Customer.Name;
				                    dto.Customer.Surname = arg.Customer.Surname;
				                    dto.Customer.Mobile = arg.Customer.Mobile;
				                    dto.Customer.Email = arg.Customer.Email;
				                    dto.Customer.CustImgPath = arg.Customer.CustImgPath;
				                    dto.Customer.Password = arg.Customer.Password;
				                    dto.Customer.CarImgPath = arg.Customer.CarImgPath;
				                    dto.Customer.CarBrand = arg.Customer.CarBrand;
				                    dto.Customer.CarModel = arg.Customer.CarModel;
				                    dto.Customer.InsurancePackage = arg.Customer.InsurancePackage;
				                    dto.Customer.Code = arg.Customer.Code;
								}
												dto.RegistrationId = arg.RegistrationId;
							            }
            return dto;
        }

        private SessionInfo TransformDto2SessionInfo(SessionInfoDto arg)
        {
            //var obj = new SessionInfo();
			var obj = _session.Get("SessionInfo", arg.Id) as SessionInfo;
            if (obj == null)
                obj = new SessionInfo();
            if (null != arg)
            {
			                obj.Id = arg.Id;
			                obj.UpdateTime = arg.UpdateTime;
			                obj.SessionId = arg.SessionId;
						obj.Surveyor = EntityMapper(obj.Surveyor, arg.Surveyor);
						obj.Customer = EntityMapper(obj.Customer, arg.Customer);
			                obj.RegistrationId = arg.RegistrationId;
			            }
            return obj;
        }
        #endregion

		  			#region Shared private methods
        private TEntity EntityMapper<TEntity, TModel>(TEntity te, TModel tm)
        {
            try
            {
                Type tmType = tm.GetType();
                PropertyInfo propTm = tmType.GetProperty("Id");
                if (propTm == null)
                    throw new ProperityNotFoundException();

                if (te != null)
                {
                    Type teType = te.GetType();
                    PropertyInfo propTe = teType.GetProperty("Id");
                    if (!propTe.GetValue(te, null).Equals(propTm.GetValue(tm, null)))
                    {
                        te = (TEntity)_session.Get(typeof(TEntity).Name, propTm.GetValue(tm, null));
                    }
                }
                else
                {
                    te = (TEntity)_session.Get(typeof(TEntity).Name, propTm.GetValue(tm, null));
                }
                return te;
            }
            catch (ProperityNotFoundException)
            {
                return te;
            }
            catch (Exception e)
            {
                return te;
            }
        }

        #endregion
    }
	class ProperityNotFoundException : Exception
    { 
        public ProperityNotFoundException() : base() { }
        public ProperityNotFoundException(string message) : base(message) { }
    }
}


